# -*- coding: utf-8-unix; fill-column: 95; -*-

###############################################################################################
#
# This file is part of Escapade Trip Planner, a social web application for creating and
# sharing motorcycle roadmaps.
#
# Copyright © 2011, Pierre-François Gomez <pef.gomez@gmail.com>
#
# Escapade Trip Planner is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software Foundation, either
# version 3 of the License, or (at your option) any later version.
#
# Escapade Trip Planner is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with Escapade Trip
# Planner. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################################

import escapade.backend.mapquest
import escapade.backend.shelve

from escapade.core.roadmap import Roadmap

class MapItemStore:
    def __init__(self):
        self.backend = escapade.backend.mapquest.MapItemBackend()

    def item(self):
        raise(NotImplementedError)

    def search(self, query_string):
        raise(NotImplementedError)

class RoadmapStore:
    def __init__(self):
        self.backend = escapade.backend.shelve.RoadmapBackend()

    def create(self, p_roadmap):
        l_roadmap = Roadmap(**p_roadmap)
        return(self.backend.create(l_roadmap.read()))

    def read(self):
        def _summary(l_id):
            return Roadmap(**self.backend.item(l_id)).summary()
        return([ _summary(l_id) for l_id in self.backend.read() ])

    def update(self, p_roadmap):
        l_roadmap = Roadmap(**p_roadmap)
        return(self.backend.update(l_roadmap.read()))

    def delete(self, p_id):
        self.backend.delete(p_id)

    def contains(self, p_id):
        return(self.backend.contains(p_id))

    def item(self, p_id):
        l_roadmap = Roadmap(**self.backend.item(p_id))
        return(l_roadmap.read())

    def search(self, query_string):
        raise(NotImplementedError)
